package com.atlantis.apps.socius.util;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

import com.atlantis.apps.socius.model.SNMailData;

public class SNUtility {
	public static void updateSongView(Context c) throws Exception {
		@SuppressWarnings("unused")
		SNMailData mailData;
		SharedPreferences mySharedPreferences = c.getSharedPreferences(SNConstants.SNSETTINGS, Activity.MODE_PRIVATE);

		if (mySharedPreferences != null) {

/*			SNMailUtility mail = new SNMailUtility(mySharedPreferences.getString(SNConstants.SNEMAIL, ""),
					mySharedPreferences.getString(SNConstants.SNPASSWORD, ""));

			mailData = mail.read();
			SharedPreferences.Editor editor = mySharedPreferences.edit();

			
			 * now store your primitive type values. In this case it is
			 * true, 1f and Hello! World
			 
			editor.putString(SNConstants.SNNOOFSONGS, String.valueOf(mailData.getUnreadEmailCount()));
			editor.putString(SNConstants.SNPREVLASTUPDATE,
					String.valueOf(mySharedPreferences.getString(SNConstants.SNLASTUPDATE, "")));
			editor.putString(SNConstants.SNLASTUPDATE, String.valueOf(mailData.getLastReadDate()));
			// save the changes that you made
			editor.commit();

			Log.d(c.getClass().getSimpleName(), "Updated Songs data");
			Log.d(c.getClass().getSimpleName(), mySharedPreferences.getString(SNConstants.SNLASTUPDATE, ""));
			Log.d(c.getClass().getSimpleName(), mySharedPreferences.getString(SNConstants.SNPREVLASTUPDATE, ""));

			if (!mySharedPreferences.getString(SNConstants.SNPREVLASTUPDATE, "").equals(
					String.valueOf(mySharedPreferences.getString(SNConstants.SNLASTUPDATE, "")))) {
				NotificationManager mNotificationManager = (NotificationManager) c
						.getSystemService(Context.NOTIFICATION_SERVICE);

				CharSequence text = c.getText(R.string.songsupdated);
				Notification notification = new Notification(R.drawable.stat_happy, text, System.currentTimeMillis());
				PendingIntent contentIntent = PendingIntent.getActivity(c, 0, new Intent(c, SNMainActivity.class), 0);
				notification.setLatestEventInfo(c, c.getText(R.string.servicename), text, contentIntent);
				notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
				mNotificationManager.notify(1, notification);

			}
		} else {
			Toast.makeText(c, R.string.settingserror, Toast.LENGTH_LONG).show();
			Log.d(c.getClass().getSimpleName(), "Check your Settings!");
*/		}
	}

	public static boolean sendRating(Context c, String rating) {

		boolean returnval = false;
/*		try {
			SharedPreferences mySharedPreferences = c.getSharedPreferences(SNConstants.SNSETTINGS, Activity.MODE_PRIVATE);

			if (mySharedPreferences != null) {

				SNMailUtility mail = new SNMailUtility(mySharedPreferences.getString(SNConstants.SNEMAIL, ""),
						mySharedPreferences.getString(SNConstants.SNPASSWORD, ""));

				String[] _to = new String[1];
				_to[0] = mySharedPreferences.getString(SNConstants.SNEMAIL, "");

				mail.set_body("Rating for the day");
				mail.set_subject("Rating for the day - " + rating);
				mail.set_from(mySharedPreferences.getString(SNConstants.SNEMAIL, ""));
				mail.set_to(_to);
				returnval = mail.send();
			}
		} catch (Exception e) {
			Toast.makeText(c, R.string.generalerror, Toast.LENGTH_LONG).show();
			Log.e(c.getClass().getSimpleName(), "Some issue in sending rating email!!! ", e);
		}
*/		return returnval;
	}

}
